const koa = require('koa')
const router = require('koa-router')()
const bodyparser = require('koa-bodyparser')
const cors = require('koa2-cors')
const static = require('koa-static')

const client = require('./routes/client/index')

const app = new koa()

// 配置处理后端跨域
app.use(cors())
// 接收参数
app.use(bodyparser())
// 暴露出 static 文件夹下的文件 可以直接访问
app.use(static(__dirname + '/static'))

// 配置接口
router.get('/test', async ctx => {
	ctx.body = { code: 200, result: 'get /test is connect!!!' }
})

router.post('/demo', async ctx => {
	ctx.body = { code: 200, result: 'post /demo is connect!!!' }
})

router.use('/client', client)

app.use(router.routes())

app.listen('666', () => {
	//监听端口
	console.log('server is running in port 666! ')
})
